<template>
  <div>
    <!--条件筛选-->
    <TopFilter ref="topFilter" :list="topFilterList" :cols="3" labelWidth="110" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>

    <button-area :style="{ paddingLeft: '80px' }"></button-area>
    <FilterTable
      ref="table"
      columnsRef="testindex"
      :isExportExcel2="true"
      exportFileName="电池预约经销商对应关系.xlsx"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :isSelectColumn="false"
      :datakey="'records'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectData"
    >
      <template slot="controls">
        <el-button size="small" type="primary" icon="el-icon-plus" @click="detailHandle(null,'add')">新增</el-button>
      </template>
    </FilterTable>

    <!-- 编辑窗口 -->
    <Drawer
      :visible.sync="visibleDrawer"
      title="电池维修对应关系维护"
      :width="920"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
       >
      <info-model v-model="initData" @close="infoClose" />
    </Drawer>

    <BaseDialog
      :visible.sync="issearch"
      :title="'经销商查询'"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <ownerSeacher  @close="dealercloseHandler" />
    </BaseDialog>

    <BaseDialog
      :visible.sync="issearch2"
      :title="'经销商查询'"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <ownerSeacher  @close="dealercloseHandler2" />
    </BaseDialog>
  </div>
</template>

<script>
import ownerSeacher from './ownerSeacher';
import infoModel from './infoModel';
import { getRelationshipData } from '@/api/serviceass/batteryService/relationship';
import { dictionary } from '@/utils/dictMixin';
export default {
  name: 'servicessbatteryservicerelationshipindex',
  mixins: [dictionary],
  components: {
    infoModel,
    ownerSeacher
  },
  data() {
    return {
      topFilterList: this.createTopFilterList(),
      columns: this.createTableColumns(),
      fetchParams: { xhrAbort: true },
      fetchApi: getRelationshipData,
      visibleDrawer: false,
      initData: {},
      issearch: false,
      issearch2: false
    }
  },
  methods: {
    createTopFilterList() {
      return [
        {
          type: 'SELECT',
          label: '电池品牌:',
          fieldName: 'fwdcpp',
          placeholder: '请选择...',
          itemList: this.createDictList('5014')
        },
        {
          type: 'SELECT',
          label: '启用标记:',
          fieldName: 'xtqybz',
          placeholder: '请选择...',
          itemList: this.createDictList('1003')
        },
        {
          type: 'INPUT',
          label: '经销商名称',
          fieldName: 'jxcode',
          placeholder: '请选择',
          unitRender: () => {
            return (
              <div>
                <el-button icon="el-icon-search" onClick={() => this.seacherFun()}></el-button>
              </div>
            );
          },
          change:p=>{
            if(!p){
              this.dealerCode=''
            }
          }
        },
        {
          type: 'INPUT',
          label: '对应经销商名称',
          fieldName: 'dycode',
          placeholder: '请选择',
          unitRender: () => {
            return (
              <div>
                <el-button icon="el-icon-search" onClick={() => this.seacherFun2()}></el-button>
              </div>
            );
          },
          change:p=>{
            if(!p){
              this.dealerCode=''
            }
          }
        },
      ]
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 50,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <multiuse-button  size="mini" type="text" onClick={() => this.detailHandle(props.row, 'edit')}>
                  编辑
                </multiuse-button>
              </div>
            );
          }
        },
        {
          title: '电池品牌',
          dataIndex: 'fwdcpp',
          sorter: true,
          dictItems: this.createDictList('5014')
        },
        {
          title: '经销商代码',
          dataIndex: 'jxcode',
          sorter: true,
        },
        {
          title: '经销商名称',
          dataIndex: 'jxname',
          sorter: true,
        },
        {
          title: '对应经销商代码',
          dataIndex: 'dycode',
          sorter: true,
        },
        {
          title: '对应经销商名称',
          dataIndex: 'dyname',
          sorter: true,
        },
        {
          title: '启用标记',
          dataIndex: 'xtqybz',
          sorter: true,
          dictItems: this.createDictList('1003')
        },
      ]
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    selectData(val) {
      console.info(val)
      this.tableData = val;
    },
    detailHandle(row, type) {
      this.initData =  {
        type: type,
        data: row,
        id:1001
      }; //行id
      this.visibleDrawer = true;
    },
    infoClose(rData) {
      this.visibleDrawer = false;
      if (rData.type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
    seacherFun(){
      this.issearch=true;
    },
    seacherFun2(){
      this.issearch2=true;
    },
    dealercloseHandler(val){
      console.info(val)
      if(val){
        this.topFilterList.find(x=>x.fieldName=='jxcode').initialValue=val.dealerCode;
        this.fetchParams=Object.assign({
          dealerCode: val.dealerCode
        },this.fetchParams)
        this.dealerCode=val.dealerCode
      }
      this.issearch=false;
    },
    dealercloseHandler2(val){
      console.info(val)
      if(val){
        this.topFilterList.find(x=>x.fieldName=='dycode').initialValue=val.dealerCode;
        this.fetchParams=Object.assign({
          dealerCode: val.dealerCode
        },this.fetchParams)
        this.dealerCode=val.dealerCode
      }
      this.issearch2=false;
    },
  }
}
</script>
